package com.example.service;

import com.example.entity.Card;
import com.example.mapper.CardMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*  的逻辑层
**/
@Service
@RequiredArgsConstructor
public class CardService {

   private final CardMapper cardMapper;

   /**
   * 增
   **/
   public void add(Card card) {
       cardMapper.insert(card);
   }

   /**
   * 删
   **/
   public void deleteById(Integer id) {
       cardMapper.deleteById(id);
   }

   /**
   * 批量删除
   **/
   public void deleteBatch(List<Integer> ids) {
       for (Integer id : ids) {
       cardMapper.deleteById(id);
       }
   }

   /**
   * 改
   **/
   public void updateById(Card card) {
       cardMapper.updateById(card);
   }

   /**
   * 根据ID查询
   **/
   public Card selectById(Integer id) {
       return cardMapper.selectById(id);
   }

   /**
   * 查询所有
   **/
   public List<Card> selectAll(Card card) {
       card.setUserId(TokenUtils.getCurrentUser().getId());
       return cardMapper.selectAll(card);
   }

   /**
   * 分页查询
   **/
   public PageInfo<Card> selectPage(Card card, Integer pageNum, Integer pageSize) {
       PageHelper.startPage(pageNum, pageSize);
       List<Card> list = cardMapper.selectAll(card);
       return PageInfo.of(list);
   }

}